/**   
 * 项目名：五位一体化工安全信息平台
 * 日期：    2020-01-10 17:30:23  
 * Copyright (c) 2015- joysuch-版权所有     
 */

package com.joysuch.wwyt.risk.service;

import java.util.List;

import com.joysuch.wwyt.core.exception.BusinessRestrictionsException;
import com.joysuch.wwyt.risk.bean.RiskEvaluationRepoListBean;
import com.joysuch.wwyt.risk.bean.RiskEvaluationRepoListBean.Search;
import com.joysuch.wwyt.risk.entity.RiskEvaluationRepo;
import com.joysuch.wwyt.risk.entity.RiskPoint;
import com.joysuch.wwyt.risk.entity.RiskPointEvaluationJha;
import com.joysuch.wwyt.risk.entity.RiskPointEvaluationScl;
import com.joysuch.wwyt.risk.enums.EvaluationStates;
import com.joysuch.wwyt.risk.enums.EvaluationTypes;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

public interface RiskEvaluationRepoService {

    Page<RiskEvaluationRepoListBean> findByPage(Pageable page, Search condition, EvaluationTypes type,
            EvaluationStates states);

    void delete(Long id) throws BusinessRestrictionsException;

    RiskEvaluationRepo findById(Long id);

    void update(RiskEvaluationRepo repo);

    /**
     * 添加风险点评估报告记录
     * 
     * @param riskPointId
     *            风险点ID
     * @param type
     *            报告类型。JHA/SCL等
     * @param method
     *            测评方法, LSR,LEC等
     * @param evaluationId
     *            评估记录ID
     * @param state
     *            评估状态
     * @param riskLevel
     *            评估级别
     * @return
     */
    public RiskEvaluationRepo addRiskPointEvaluation(RiskPoint riskPoint, Long riskDistrictId, EvaluationTypes type,
            String method,
            Long evaluationId, EvaluationStates state, Integer riskLevel);

    /**
     * 添加风险点评估报告记录
     * 
     * @param riskPointId
     *            风险点ID
     * @param type
     *            报告类型。JHA/SCL等
     * @param method
     *            测评方法, LSR,LEC等
     * @param evaluationId
     *            评估记录ID
     * @param state
     *            评估状态
     * @param riskLevel
     *            评估级别
     * @param template
     *            模板模式
     * @return
     */
    public RiskEvaluationRepo addRiskPointEvaluation(RiskPoint riskPoint, Long riskDistrictId, EvaluationTypes type,
            String method,
            Long evaluationId, EvaluationStates state, Integer riskLevel, boolean template);

    /**
     * 更新风险点静态评估状态为指定状态。将指定ID评估记录排除在外
     * 静态评估是指对风险点进行的非作业评估，一次评估生效后，将覆盖之前的静态评估。
     * 
     * @param riskPointId
     *            风险点ID
     * @param type
     *            评估类型
     * @param state
     *            更改为状态
     * @param excludeEvaluationId
     *            需要排除的评估记录ID
     */
    public void updateStateForStaticEvaluationOfRiskPoint(Long riskPointId, EvaluationTypes type,
            EvaluationStates state, Long excludeEvaluationId);

    /**
     * 更新评估相关的模块信息。
     * 
     * @param id
     *            评估ID
     * @param module
     *            模块名称
     * @param moduleId
     *            模块ID
     */
    public void updateRelatedWorkSafetyCertInfo(Long id, Long moduleId);

    /**
     * 评估生效。用于关联业务需要审核，审核成功后评估才生效的场景。如作业证。<br>
     * 1. 更新评估状态
     * 2. 根据评估类型，更改风险点、风险区域的评估级别
     * 
     * @param id
     *            评估ID
     */
    public void evaluationTakeEffect(Long id);

    public void evaluationAuditFail(Long id);

    /**
     * 评估过期。用于作业证验收后，主动过期风险分级
     * 
     * @param id
     *            评估ID
     */
    public void evaluationOutOfDate(Long id);

    public List<RiskEvaluationRepo> findByRiskPointIdAndState(Long riskPointId, EvaluationStates state);

    /**
     * 查找风险点指定类型的风险值最高的评估记录
     * 
     * @param riskPointId
     *            风险点ID
     * @param type
     *            风险类型
     * @return 评估记录
     */
    public RiskEvaluationRepo findMostImportantByRiskPointIdAndType(Long riskPointId, EvaluationTypes type);

    /**
     * 寻找当前生效的非作业评估的指定类型评估记录
     * 
     * @param riskPointId
     *            风险点ID
     * @param type
     *            评估类型
     * @return
     */
    public RiskEvaluationRepo findMostImportantNotFromWorkSafetyCertByRiskPointIdAndType(Long riskPointId,
            EvaluationTypes type);

    public RiskPointEvaluationJha findMostImportantJhaOfRiskPoint(Long riskPointId);

    public RiskPointEvaluationJha findLatestJhaEvaluation();

    public RiskPointEvaluationScl findMostImportantSclOfRiskPoint(Long riskPointId);

    public RiskEvaluationRepo findTemplateOfRiskPoint(Long riskPointId, EvaluationTypes type);

    public RiskPointEvaluationScl findLatestSclEvaluation();

    List<Long> findAllEvaluationIdsOfType(EvaluationTypes type);

    /**
     * 查找区域中最高的有效作业证风险级别
     * 
     * @param riskDistrictId
     *            风险区域ID
     * @return
     */
    Integer findMostImportWorkSafetyCertRiskLevelOfDistrict(Long riskDistrictId);

}
